package com.zhu.tool_test.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linktopa.framework.common.model.response.ResponseResult;
import com.zhu.tool_test.dao.DeviceMapper;
import com.zhu.tool_test.entity.Device;
import com.zhu.tool_test.response.DataFactory;
import com.zhu.tool_test.response.Messages;
import com.zhu.tool_test.service.IDeviceService;
import com.zhu.tool_test.spring_cache.anno.GgCacheEvict;
import com.zhu.tool_test.spring_cache.anno.GgCacheable;
import com.zhu.tool_test.starke.matrix.multipart.core.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ggBall
 * @since 2020-12-27
 */
@Service
@Slf4j
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements IDeviceService {


    /**
     *新增
     * @param device 设备实体类
     * @return
     */
    @Override
    @CachePut(cacheNames="device",key="#device.id")
    public void insert(Device device){
         save(device);
    }

    /**
     * 删除
     * @param id 主键id
     * @return
     */
    @Override
    //@CacheEvict(cacheNames = "device",key = "id")
    @GgCacheEvict(value = DeviceMapper.class,key = "ent")
    public boolean deleteById(Long id) {
        return removeById(id);
    }

    /**
     * 更新
     * @param device
     * @return
     */
    @Override
    public Boolean updateDevice(Device device){
        boolean update = updateById(device);
        log.info("device update after : {}",device);
        return update;
    }

    /**
     * 查询全部设备
     *
     * @return
     */
    @Override
    //@Cacheable(cacheNames = "device")
    @GgCacheable(value = ArrayList.class,key = "ent")
    public  List<Device> allDevices() {
        List<Device> list = list();
        return list;
    }




}
